home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Developer & Web Development Tools / Inno Setup 5.2.3 / isetup-5.2.3.exe / {app} / Examples / CodeDll.iss (.txt) < prev    next >
Encoding:
Inno Setup Script  |  2007-12-06  |  2.6 KB  |  56 lines

  1. ; -- CodeDll.iss --
  2. ; This script shows how to call DLL functions at runtime from a [Code] section.
  3. [Setup]
  4. AppName=My Program
  5. AppVerName=My Program version 1.5
  6. DefaultDirName={pf}\My Program
  7. DisableProgramGroupPage=yes
  8. UninstallDisplayIcon={app}\MyProg.exe
  9. OutputDir=userdocs:Inno Setup Examples Output
  10. [Files]
  11. Source: "MyProg.exe"; DestDir: "{app}"
  12. Source: "MyProg.chm"; DestDir: "{app}"
  13. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  14. ; Install our DLL to {app} so we can access it at uninstall time
  15. ; Use "Flags: dontcopy" if you don't need uninstall time access
  16. Source: "MyDll.dll"; DestDir: "{app}"
  17. [Code]
  18. const
  19.   MB_ICONINFORMATION = $40;
  20. //importing a Windows API function
  21. function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  22. external 'MessageBoxA@user32.dll stdcall';
  23. //importing a custom DLL function, first for Setup, then for uninstall
  24. procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  25. external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
  26. procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  27. external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
  28. //importing a function for a DLL which might not exist at runtime
  29. procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  30. external 'DllFunc@DllWhichMightNotExist.dll stdcall delayload';
  31. function NextButtonClick(CurPage: Integer): Boolean;
  32.   hWnd: Integer;
  33. begin
  34.   if CurPage = wpWelcome then begin
  35.     hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
  36.     MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
  37.     MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  38.     try
  39.       //if this DLL does not exist (it shouldn't), an exception will be raised
  40.       DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
  41.     except
  42.       //handle missing dll here
  43.     end;
  44.   end;
  45.   Result := True;
  46. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  47. begin
  48.   // Call our function just before the actual uninstall process begins
  49.   if CurUninstallStep = usUninstall then
  50.   begin
  51.     MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  52.     // Now that we're finished with it, unload MyDll.dll from memory.
  53.     // We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
  54.     UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
  55.   end;
  56.